package com.learn.springbootcache.mapper;

import com.learn.springbootcache.bean.ChinaCity;
import com.learn.springbootcache.bean.ChinaCounty;
import com.learn.springbootcache.bean.ChinaProvince;
import com.learn.springbootcache.bean.ChinaRegion;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Jmy
 * @date 2019/10/18 15:07
 * @email jiaomingyu5778@gmail.com
 */
@Mapper
@Repository
public interface ChinaProvinceMapper {

    /**
     * 查询中国的省份，无需查询条件
     * @return 数据库所有的数据
     */
    @Select("SELECT p.province_id,p.province_name FROM china_province p")
    List<ChinaProvince> findAllList();

    @Select("SELECT c.province_id,c.city_id,c.city_name FROM china_city c WHERE province_id = #{provinceId}")
    List<ChinaCity> findCityByProvinceId(Integer provinceId);

    @Select("SELECT c.city_id,c.county_id,c.county_name FROM china_county c WHERE city_id = #{cityId}")
    List<ChinaCounty> findCountyByCityId(Integer provinceId);

    @Select("SELECT c.county_id,c.town_id,c.town_name FROM china_region c WHERE county_id = #{countyId}")
    List<ChinaRegion> findRegionByCountyId(Integer countyid);

    @Select("SELECT * FROM china_region c WHERE id = #{id}")
    ChinaRegion findRegionById(Integer id);
}
